/**
 * 
 */
package neptune.web.server.operations;

import java.util.Map;

import it.robertobifulco.ias.IncorrectParamsException;
import it.robertobifulco.ias.Operation;
import neptune.web.server.ApplicationManager;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class StartExperiment implements Operation {

	public static String ID = "StartExperiment";

	/*
	 * (non-Javadoc)
	 * 
	 * @see it.robertobifulco.ias.Operation#execute(java.lang.Object[])
	 */
	/**
	 * @param args
	 *            [0] = String expId
	 */
	@SuppressWarnings("unchecked")
	public Object[] execute(Object[] args) throws IncorrectParamsException,
			Exception {

		// TODO modificare imponendo la chiamata a startExperiment e non ad
		// allocateExperiment
		// non e' stato gia' fatto per risolvere
		// momentaneamente il problema del no route to host

		String expId = (String) args[0];

		if (args.length == 2) {
			Map<String, String[]> allocationMap = (Map<String, String[]>) args[1];

			ApplicationManager.getApplicationManager().getNeptuneManager()
					.allocateExperiment(expId, allocationMap);

		} else
			ApplicationManager.getApplicationManager().getNeptuneManager()
					.allocateExperiment(expId);

		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see it.robertobifulco.ias.Operation#getDescription()
	 */
	public String getDescription() {
		return "Executes the SwapIn and SetUp operation for an experiment";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see it.robertobifulco.ias.Operation#getID()
	 */
	public String getID() {
		return ID;
	}

}
